<template>
  <svg v-if="iconName" :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" :fill="color" />
  </svg>
</template>

<script>
export default defineComponent({
  props: {
    iconClass: {
      type: String,
      default: undefined
    },
    className: {
      type: String,
      default: ''
    },
    loading: {
      type: Boolean,
      default: false
    },
    color: {
      type: String,
      default: ''
    },
  },
  setup(props) {
    return {
      iconName: computed(() => `#icon-${ props.iconClass ? props.iconClass : props.loading ? 'loading' : undefined }`),
      svgClass: computed(() => {
        const className = ['svg-icon']
        if (props.loading) className.push('svg-loading')
        if (props.className) className.push(props.className)
        return className.join(' ')
      })
    }
  }
})
</script>

<style scope lang="scss">
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}

.svg-external-icon {
  background-color: currentColor;
  mask-size: cover !important;
  display: inline-block;
}

.svg-loading {
  color: #409EFF;
  font-size: 1.2rem;
  animation: rotating 2s linear infinite;
}
</style>
